package cn.beforedark.yygh.common.exception;


import cn.beforedark.yygh.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R handleException(Exception ex){
        log.error(ex.getMessage());
        ex.printStackTrace();
        return R.error().message("系统 500 异常！");
    }


    @ExceptionHandler(YyghException.class)
    public R handleYyghException(YyghException ex){
        log.error(ex.getMessage());
        return R.error().message(ex.getMessage()).code(ex.getCode());
    }

}
